﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using OpenNETCF.WindowsCE;
using OpenNETCF.WindowsCE.Notification;

namespace MoneyTrackin
{
    public partial class MainForm : Form
    {
        EditForm editForm = new EditForm();
        public MainForm()
        {
            DeviceManagement.NetworkConnected += new OpenNETCF.WindowsCE.DeviceNotification(DeviceManagement_NetworkConnected);
            InitializeComponent();
            dataGrid.DataSource = Logic.Instance.DataSet.Transactions;

            Logic.Instance.DataSet.Transactions.TableCleared += new DataTableClearEventHandler(Transactions_Updated);
            Logic.Instance.DataSet.Transactions.TableNewRow += new DataTableNewRowEventHandler(Transactions_Updated);
            Logic.Instance.DataSet.Transactions.TransactionsRowChanged += new DataSet1.TransactionsRowChangeEventHandler(Transactions_Updated);
            Logic.Instance.DataSet.Transactions.TransactionsRowDeleted += new DataSet1.TransactionsRowChangeEventHandler(Transactions_Updated);
        }

        private void Transactions_Updated(object sender, EventArgs e)
        {
            dataGrid.Update();
        }

        private void DeviceManagement_NetworkConnected()
        {
            //logic.SubmitAllTransactions();
        }

        private void menuItemExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }

        private void menuItemAdd_Click_1(object sender, EventArgs e)
        {
            editForm.BindingSource.Position = Logic.Instance.DataSet.Transactions.Rows.Count;
            editForm.ShowDialog();
        }

        private void menuItemEdit_Click(object sender, EventArgs e)
        {
            editForm.BindingSource.Position = dataGrid.CurrentRowIndex;
            editForm.ShowDialog();
        }

        private void menuItemDelete_Click(object sender, EventArgs e)
        {
            Logic.Instance.DataSet.Transactions.Rows.RemoveAt(dataGrid.CurrentRowIndex);
        }
    }
}